<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户名" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="请输入用户手机号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="结算银行" prop="gradeCode">
        <el-input v-model="queryParams.bankName" placeholder="请输入结算银行" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['pos:TUserInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="TUserInfoList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="用户id" align="center" prop="userId" v-if="false" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="用户头像" align="center" prop="userImg">
        <template slot-scope="scope">
          <el-popover placement="left" trigger="click" width="400">
            <img :src="scope.row.userImg" width="100%" />
            <img slot="reference" :src="scope.row.userImg" :alt="scope.row.userImg"
              style="max-height: 50px;max-width: 50px; padding: 5px" />
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="用户手机号" align="center" prop="userPhone" />
      <el-table-column label="身份证号" align="center" prop="identityMark" />
      <el-table-column label="结算银行" align="center" prop="bankName" />
      <el-table-column label="银行卡号" align="center" prop="bankCardMark" />
      <el-table-column label="审核状态" align="center" prop="auditStatusDescribe" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px;">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.auditStatus=='0'" icon="el-icon-edit" @click="handlePass(scope.row)"
            v-hasPermi="['pos:TUserInfo:edit']">通过</el-button>
          <el-button size="mini" type="text" v-if="scope.row.auditStatus=='0'" icon="el-icon-edit" @click="handleRefuse(scope.row)"
            v-hasPermi="['pos:TUserInfo:edit']">拒绝</el-button>
          <el-button size="mini" type="text" icon="el-icon-detail" @click="handleDetail(scope.row)"
            v-hasPermi="['pos:TUserInfo:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 审核不通过对话框 -->
    <el-dialog :title="title" :visible.sync="checkDiaLog" append-to-body>
      <el-form :model="checkForm" ref="checkForm" :inline="true" v-show="showSearch">
        <el-form-item label="拒绝原因" prop="auditStatusDescribe">
          <el-input type="textarea" v-model="checkForm.auditStatusDescribe" placeholder="拒绝原因" :row="5"
            style="width: 500px;" />
        </el-form-item>
        <br />
        <el-row type="flex" class="row-bg" justify="center">
          <el-button type="primary" @click="submitCheckForm" la>确 定</el-button>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {
    checkListTUserInfo,
    getTUserInfo,
    exportCheckTUserInfo,
    checkPass,
    checkRefuse
  } from "@/api/pos/TUserInfo";

  export default {
    name: "indexCheck",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户基础数据表格数据
        TUserInfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        checkDiaLog: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: null,
          userPhone: null,
          gradeCode: null
        },
        // 表单参数
        checkForm: {
          auditStatusDescribe: null
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询用户基础数据列表 */
      getList() {
        this.loading = true;
        checkListTUserInfo(this.queryParams).then(response => {
          this.TUserInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.checkDiaLog = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.resetForm("checkForm");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 重置按钮操作 */
      resetQueryTeam() {
        this.resetForm("checkForm");
        this.handleTeamQuery();
      },
      /** 查询详情按钮操作 */
      handleDetail(row) {
        const userId = row.userId || this.ids[0];
        this.$router.push({
          path: "/TUserInfo/userManage/userCheckDetail",
          query: {
            userId: userId
          }
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 通过按钮操作 */
      handlePass(row) {
        this.$confirm('确定审核通过该认证信息吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.checkForm.userId = row.userId || this.ids;
          console.log("-1--", row.id);
          console.log("---", this.checkForm);
          checkPass(this.checkForm).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.getList();
          });
        }).catch(() => {});
      },
      /** 拒绝按钮操作 */
      handleRefuse(row) {
        this.reset();
        const userId = row.userId || this.ids
        getTUserInfo(userId).then(response => {
          this.checkForm = response.data;
          this.checkDiaLog = true;
          this.title = "审核不通过";
        });
      },
      /** 提交按钮 */
      submitCheckForm() {
        this.$refs["checkForm"].validate(valid => {
          if (valid) {
            checkRefuse(this.checkForm).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.checkDiaLog = false;
              this.getList();
            });
          }
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有用户基础数据数据项？').then(() => {
          this.exportLoading = true;
          return exportCheckTUserInfo(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>
